//
//  StoreCategoryPicker.m
//  YongChuanTradingArea
//
//  Created by 李冰 on 2017/10/12.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "StoreCategoryPicker.h"
@interface StoreCategoryPicker()<UIPickerViewDataSource, UIPickerViewDelegate>
/** 1.选中的字符串 */
@property (nonatomic, strong, nullable)StoreCategoryModel *selectModel;
@end
@implementation StoreCategoryPicker

#pragma mark - --- init 视图初始化 ---
- (void)setupUI
{
    [super setupUI];
    
    _arrayData = @[].mutableCopy;
    _heightPickerComponent = 44;
    _widthPickerComponent = 200;
    
    [self.pickerView setDelegate:self];
    [self.pickerView setDataSource:self];
}

#pragma mark - --- delegate 视图委托 ---

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{

    return self.arrayData.count;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return self.heightPickerComponent;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{

    return self.widthPickerComponent;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.selectModel = self.arrayData[row];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view
{

    UILabel *label = [[UILabel alloc]init];
    [label setText:[self.arrayData[row] Name]];
    [label setTextAlignment:NSTextAlignmentCenter];
    return label;
}

- (void)selectedOk
{
    self.selectBlock(self.selectModel);
    [super selectedOk];
}

- (void)setArrayData:(NSMutableArray<StoreCategoryModel *> *)arrayData
{
    _arrayData = arrayData;
    _selectModel = arrayData.firstObject;
    [self.pickerView reloadAllComponents];
}

@end
